package objbo.xmlparser.controls.action;

import java.net.URI;

import objbo.xmlparser.controls.ControlMain;
import objbo.xmlparser.view.interfaces.FileInterFace;
import objbo.xmlparser.view.interfaces.UIInterFace;
import objbo.xmlparser.view.ui.FileControlUI;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Text;

public class FileSaveAction extends Action
{
	private UIInterFace uIInterFace = null;
	private FileInterFace fileInterFace = null;
	private FileControlUI ui = null;
	private URI fileURI = null;
	
	
	public FileSaveAction(FileInterFace fileInterFace, UIInterFace uIInterFace)
	{
		this.fileInterFace = fileInterFace;
		this.uIInterFace = uIInterFace;
	}
	
	public void setFileControlUI(FileControlUI ui)
	{
		this.ui = ui;
	}
	
	public void setFileURI(URI fileURI)
	{
		this.fileURI = fileURI;
	}
	
	@Override
	public void run()
	{
		if(this.ui != null )
		{
			if(this.ui.getFilePath() == null || ui.getFilePath().equals(""))
			{
				return;
			}
			
			this.fileInterFace.fileSave(ui.getFilePath());
			this.uIInterFace.refreshTreeUI();
		}
		
		else if(this.fileURI != null)
		{
			this.fileInterFace.fileSave(this.fileURI);
		}
	}
}
